package com.blog.web.controller;

import com.blog.common.core.domain.R;
import com.blog.common.core.web.domain.AjaxResult;
import com.blog.common.core.web.page.TableDataInfo;
import com.blog.common.domain.vo.ArticleHomeVo;
import com.blog.common.domain.vo.TagVo;
import com.blog.web.service.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 标签控制器
 * </p>
 *
 * @author Valerie
 * @date 2023/3/1
 **/
@Api(tags = "标签模块")
@RestController
public class TagController {

    @Resource
    private TagService tagService;

    /**
     * 查询标签列表
     *
     * @return {@link R<TableDataInfo<TagVo>>} 标签列表
     */
    @ApiOperation(value = "查询标签列表")
    @GetMapping("/tags")
    public R<TableDataInfo<TagVo>> listTags() {
        return R.ok(tagService.listTags());
    }

    /**
     * 根据标签查询文章
     *
     * @return {@link R<List<ArticleHomeVo>>} 标签列表
     */
    @ApiOperation(value = "根据标签查询文章")
    @GetMapping("/articlesByTags")
    public R<List<ArticleHomeVo>> listArticlesByTags(@RequestParam("tagId") Serializable tagId) {
        return R.ok(tagService.listArticlesByTags(tagId));
    }
}
